﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using YTCMS.Core;
using YTCMS.Core.YTModelBinder;

namespace YTCMS.Data.Infrastructure
{
    public interface IRepository<T> where T : class
    {
        void Add(T entity);
        void Update(T entity);
        void Update(Expression<Func<T, bool>> where);
        void Delete(T entity);
        void Delete(Expression<Func<T, bool>> where);
        T GetById(long Id);
        T GetById(string Id);
        T Get(Expression<Func<T, bool>> where);
        T Get(Expression<Func<T, bool>> where, bool NoTracking);
        IEnumerable<T> GetAll();
        IEnumerable<T> GetMany(Expression<Func<T, bool>> where);

        IQueryable<T> GetMany(Expression<Func<T, bool>> where, Order orderBy, string orderFile);
        PagedList<T> GetPageList(IQueryable<T> source, int pageIndex, int pageSize, out int pcount);

        PagedList<T> GetPageList(int pageIndex, int pageSize, out int pcount);
        PagedList<T> PageList(SearchModel searchModel, int pageIndex, int pageSize, out int pcount);

        PagedList<T> GetPageList(Expression<Func<T, bool>> where, int pageIndex, int pageSize, out int pcount);
        IEnumerable<T> ExecuteSqlCommand(string sql);
        void ExecuteSql(string sql);
        IEnumerable<T> GetMany(Expression<Func<T, bool>> where, string includeName);

        IEnumerable<T> GetMany(bool noTracking, Expression<Func<T, bool>> where);

        object ExecuteScalar(string sql);

        void ExecuteSql(string sql, object[] parameters);

        int ExecuteSqlCommand(string sql, params object[] obj);
        SqlDataReader ExecuteSqlCommand(string procName, int pageIndex, int pageSize, int userid);

        IEnumerable<T> ExecuteStoreQuery(string sql, object[] parameters);

        List<T> ExecuteStoredProcedure(string storedProcedureName, params object[] parameters);

        IEnumerable<T> GetAsyncMany(Expression<Func<T, bool>> where);
        T GetAsync(Expression<Func<T, bool>> where);
    }
}
